package com.yss.sofa.report.engine.series;

import java.io.IOException;
import java.io.Serializable;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

public abstract class Series implements Serializable{
	/**********************************************************************************************/
	public static final int TYPE_CUSTOM=-1;
	public static final int TYPE_NORMAL_BAR=0;
	public static final int TYPE_NORMAL_LINE=1;
	public static final int TYPE_NORMAL_PIE=2;
	public static final int TYPE_STACK_BAR=3;
	public static final int TYPE_STACK_AREA=4;
	public static final int TYPE_BAR_LINE=5;
	public static final int TYPE_MULTI_PIE=6;
	public static final int TYPE_SPIDER_WEB=7;
	/**********************************************************************************************/
	private static final long serialVersionUID = 440304451461946140L;
	private int type;
	
	public void assignTo(Series series){
		series.type=this.type;
	}
	public abstract Series create();
	public void read(String json) throws JsonParseException, JsonMappingException, IOException{
		ObjectMapper mapper=new ObjectMapper();
		mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		mapper.configure(org.codehaus.jackson.JsonParser.Feature.ALLOW_SINGLE_QUOTES,true);
		Series series=mapper.readValue(json, this.getClass());
		series.assignTo(this);
	}
	public void read(JsonNode json) throws JsonParseException, JsonMappingException, IOException{
		ObjectMapper mapper=new ObjectMapper();
		mapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		mapper.configure(org.codehaus.jackson.JsonParser.Feature.ALLOW_SINGLE_QUOTES,true);
		Series series=mapper.readValue(json, this.getClass());
		series.assignTo(this);
	}
	public int getType() {
		return type;
	}
	private Series(){
		super();
	}
	protected Series(int type){
		this();
		this.type=type;
	}
}
